#!/bin/bash

if [[ -z "${LOGSTASH_HOST}" || "${LOGSTASH_HOST}" == "0" || "${LOGSTASH_HOST}" == "false" ]]
then
  echo "Logstash forwarder is unconfigured, disabling it!"
  /bin/s6-svc -d /etc/s6/forwarder

  exit 0
fi

if [ -f ./setup ]
then
  source ./setup
fi

STARTCMD="/usr/bin/logstash-forwarder -config /etc/forwarder"

if [ -n "${LOGSTASH_OPTS}" ]
then
  STARTCMD="${STARTCMD} ${LOGSTASH_OPTS}"
fi

exec ${STARTCMD}
